﻿Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

Namespace System.Workflow.ComponentModel.Design
    Friend NotInheritable Class ActivityRootLayout
        Inherits DefaultWorkflowLayout
        ' Methods
        Friend Sub New(ByVal serviceProvider As IServiceProvider)
            MyBase.New(serviceProvider)
        End Sub

        Public Overrides Sub OnPaint(ByVal e As PaintEventArgs, ByVal viewPortData As ViewPortData)
            MyBase.OnPaint(e, viewPortData)
            Dim graphics As Graphics = e.Graphics
            If (((Not MyBase.parentView.RootDesigner Is Nothing) AndAlso (MyBase.parentView.RootDesigner.Bounds.Width >= 0)) AndAlso (MyBase.parentView.RootDesigner.Bounds.Height >= 0)) Then
                Dim container As GraphicsContainer = graphics.BeginContainer
                Dim matrix As New Matrix
                matrix.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend)
                Dim pts As Point() = New Point() { viewPortData.LogicalViewPort.Location }
                matrix.TransformPoints(pts)
                matrix.Translate(CSng((-pts(0).X + viewPortData.ShadowDepth.Width)), CSng((-pts(0).Y + viewPortData.ShadowDepth.Height)), MatrixOrder.Append)
                graphics.Transform = matrix
                Dim bounds As Rectangle = MyBase.parentView.RootDesigner.Bounds
                graphics.ExcludeClip(bounds)
                bounds.Inflate((DefaultWorkflowLayout.Separator.Width / 2), (DefaultWorkflowLayout.Separator.Height / 2))
                ActivityDesignerPaint.DrawDropShadow(graphics, bounds, AmbientTheme.WorkflowBorderPen.Color, 4, (LightSourcePosition.Top Or LightSourcePosition.Left), 0.2!, False)
                graphics.FillRectangle(WorkflowTheme.CurrentTheme.AmbientTheme.BackgroundBrush, bounds)
                graphics.DrawRectangle(AmbientTheme.WorkflowBorderPen, bounds)
                graphics.EndContainer(container)
            End If
        End Sub


        ' Properties
        Public Overrides ReadOnly Property Extent As Size
            Get
                Dim size As Size = If((Not MyBase.parentView.RootDesigner Is Nothing), MyBase.parentView.RootDesigner.Size, Size.Empty)
                Dim size2 As New Size((size.Width + (DefaultWorkflowLayout.Separator.Width * 2)), (size.Height + (DefaultWorkflowLayout.Separator.Height * 2)))
                Dim viewPortSize As Size = MyBase.parentView.ViewPortSize
                viewPortSize.Width = CInt((CSng(viewPortSize.Width) / (CSng(MyBase.parentView.Zoom) / 100!)))
                viewPortSize.Height = CInt((CSng(viewPortSize.Height) / (CSng(MyBase.parentView.Zoom) / 100!)))
                Return New Size(Math.Max(size2.Width, viewPortSize.Width), Math.Max(size2.Height, viewPortSize.Height))
            End Get
        End Property

    End Class
End Namespace

